package com.util;

import com.controller.TestController;
import org.springframework.util.CollectionUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author: create by God of SJF
 * @version: v1.0
 * @description: com.util
 * @date:2021/9/22
 */
public class 处理大文件 {

    public static void main(String[] args) throws Exception {
        File[] fileList = new File("/Users/libin/Desktop/分类2/").listFiles();
        File file2 = new File("/Users/libin/Desktop/分类2-切割/");
        for (File file : fileList) {
            Scanner scanner = new Scanner(file);
            List<String> list = new ArrayList<String>();
            int a = 0;
            int i = 0;
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                a++;
                list.add(line+"\r\n");
                if(a == 100000){
                    File newFile = new File(file2.getPath()+"/"+file.getName()+"-"+i);
                    TestController.writeFile(newFile.getAbsolutePath(),list);
                    list = new ArrayList<String>();
                    i++;
                    a = 0;
                }
            }
            if(!CollectionUtils.isEmpty(list)){
                File newFile = new File(file2.getPath()+"/"+file.getName()+"-"+i);
                TestController.writeFile(newFile.getAbsolutePath(),list);
            }
        }
    }
}
